<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ include file="/WEB-INF/component/commonTagLib.jsp"%>
<!DOCTYPE html>
<html>
<head>
	<title><spring:message code="message.lable.compgroupSTDcompSee"/></title>
	<%@ include file="/WEB-INF/component/commonCSS.jsp" %>
    <!--[if lt IE 9]>
        <script src="lib/js/html5shiv.min.js"></script>
        <script src="lib/js/respond.min.js"></script>
    <![endif]-->
</head>
<body class="skin-blue-light sidebar-mini fixed skin-blue-light-frame">
    <section class="content-header">
        <h1><spring:message code="message.lable.compgroupSTDcompSee"/></h1>
        <ol class="breadcrumb">
           <li><a href="${ctx}/home.jsp"><i class="fa fa-home"></i><spring:message code="message.lable.first"/></a></li>
            <li class="active"><a href="#"><spring:message code="message.lable.StdManage"/></a></li>
            <li class="active"><a href="#"><spring:message code="message.lable.compgroupStd"/></a></li>
        </ol>
    </section>
    
   <section class="content" >
        <div class=" box box-success">
            <div class="box-body">
                <div class="form-inline">
                    <div class="form-group form-group-xs">
                    	<label for = "compName1"><spring:message code="message.listForm.qiYeMingCheng"/>： </label>
                        <input class="form-control" type="text" id="compName" name="compName" placeholder="<spring:message code="message.listForm.qiYeMingCheng"/>" />
                    </div>
                    
                    <button id="selectGroupSub" type="button" class="btn btn-success btn-sm" onclick="searchForPage();"><spring:message code="message.button.seachSpacing"/></button>
                </div>
            </div>
        </div>
        <table class="jqgrid" id="gridlist"></table>
         <div id="gridpage"></div>
	    <div class=" box box-warning bottongroup">
             <label id="allOk" class="btn btn-default btn-sm" onclick='editSubComp();'><spring:message code="message.button.correlationComp"/></label>
             <label id="allOk" class="btn btn-default btn-sm" onclick='groupDelComp()'><spring:message code="message.button.mergeCancel"/></label>
             <label id="allStart" class="btn btn-default btn-sm"  onclick="batchChangeStatus(1)"><spring:message code="message.button.startSpacing"/></label>
	         <label id="allDelete" class="btn btn-default btn-sm" onclick="batchChangeStatus(2)"><spring:message code="message.button.stopSpacing"/></label>
             <label id="allOk" class="btn btn-danger btn-sm" onclick='location="compGroupList.html"'><spring:message code="message.button.getBackSpacing"/></label>
        </div>
        <%--关联下属企业 --%>
         <div  class="modal fade" id="editSubComp" tabindex="-1">
            <div class="modal-dialog" >
                <div class="modal-content">
                    <div class="modal-header bg-primary">
                        <button type="button" class="close" data-dismiss="modal" ><span >&times;</span></button>
                        <h5 class="modal-title" id="exampleModalLabel"><spring:message code="message.lable.compgroupSTDcorrelationComp"/></h5>
                    </div>
        <div class="modal-body"  style="background-color: #ecf0f5">
         <form>
           <div class=" box box-success">
            <div class="box-body" >
           		 <div class="form-inline">
                    <div class="form-group form-group-xs">
                    	<label for = "compName"><spring:message code="message.listForm.qiYeMingCheng"/>： </label>
                        <input class="form-control" type="text" id="sCompName" placeholder="<spring:message code="message.listForm.qiYeMingCheng"/>" />
                    </div>
                    
                    <button id="selectGroupSubS" type="button" class="btn btn-success btn-sm" onclick="search();"><spring:message code="message.button.seachSpacing"/></button>
                </div>
            </div>
        </div> 
       
        <div class="form-group form-group-xs">
              <table class="jqgrid col-sm-1" id="gridlist1"></table>
  			 <div id="gridpage1"></div>
       
        </div>                     
           </form>
        </div>
          <div class="modal-footer">
             <button type="button" class="btn btn-primary btn-sm" onclick="batchGroupAddComp('${compGroup.compGroupId}')"><spring:message code="message.lable.selectSpacing"/></button>
             <button type="button" class="btn btn-danger btn-sm" data-dismiss="modal"><spring:message code="message.button.cancelSpacing"/></button>
           </div>
          </div>
         </div>
        </div>
       <%--关联下属企业 --%>
    </section>
    <%@ include file="/WEB-INF/component/commonJS.jsp"%>
    <script type="text/javascript">
    
    //绑定回车
    $('#compName').bind('keydown', function(event) {
        if (event.keyCode == "13") {        //13 位电脑上回车键的位置代码
            $('#selectGroupSub').click();
        }
    }); 
  
    $("#compName").focus();//加载页面光标在第一个查询框内
    
  //绑定回车
    $('#sCompName').bind('keydown', function(event) {
        if (event.keyCode == "13") {        //13 位电脑上回车键的位置代码
            $('#selectGroupSubS').click();
        }
    }); 
  
    
    
    
        $(function () {
            $("#gridlist").jqGrid({
                url: "querystdCompGroupSubCJson.html",
                mtype: "post",
                datatype: "json",
                postData: {"tid" : "${compGroup.compGroupId}"},
                autowidth: true,
                height: 270,
                colNames: ['<spring:message code="message.jqGrid.cz"/>',
                           'id',
                           '<spring:message code="message.listForm.qiYeBianMa"/>', 
                           '<spring:message code="message.listForm.qiYeMingCheng"/>',
                           '<spring:message code="message.listForm.qiYeShuXing"/>',
                           '<spring:message code="message.listForm.zuZhiJiGouDaiMa"/>',
                           '<spring:message code="message.listForm.suoShuDiQu"/>',
							'<spring:message code="message.listForm.qiYeZhuCeLeiXing"/>',
							'<spring:message code="message.lable.status"/>',
							'<spring:message code="message.listForm.xiuGaiShiJian"/>'
							],
                colModel: [
							
							{ name: 'operate', width: 50,align:"center",sortable: false,
								formatter : function(val, opts, rowdata) {
									var str =  "<a href=\"javascript:edit('"+rowdata.compId+"','"+rowdata.compCode+"','"+rowdata.compName+"','"+rowdata.compType+"','"+rowdata.status+"');\"  style='background:url(${ctx}/lib/img/icon/icon.png) no-repeat 0px 0px' class='opIcon' title='<spring:message code="message.jqGrid.cz.bianJi"/>'></a>";
									str += "<a href='${ctx}/stdCompinfoLog/stdCompinfoLogDetail.html?compId="+ rowdata.compId+ "&compCode="+ rowdata.compCode+ "&compName="+ rowdata.compName+ "&compGroupId=${compGroup.compGroupId}'  style='background:url(${ctx}/lib/img/icon/icon.png) no-repeat -120px 0px' class='opIcon' title='<spring:message code="message.jqGrid.cz.weiHuJiLu"/>'></a>";
								return str;
							} } ,  
							{ name: 'compId', width: 100,align:"center" ,hidden:true,sortable: false},
							{ name: 'compCode', width: 100,align:"center" ,sortable: false,hidden:true},
							{ name: 'compName', width: 130,align:"center",sortable: false },
							{ name: 'compType', width: 60,align:"center",sortable: false, 
								formatter : function(val, opts,
										rowdata) {
									var str = "";
									if (rowdata.compType == 1) {
										str = "<spring:message code="message.listForm.shengChanQiYe"/>";
									}
									if (rowdata.compType == 2) {
										str = "<spring:message code="message.model.peiSongQiYe"/>";
									}
									return str;
								}
							},
							{ name: 'orgCode', width: 60,align:"center",sortable: false },
                            { name: 'arFullname', width: 60,align:"center",sortable: false },
                            { name: 'compRegName', width: 60,align:"center",sortable: false },
                            { name: 'status', width: 40,align:"center",sortable: false,
                            	cellattr:function (rowId, val, rawObject, cm) {
                                    if(val == '停用'){
                                        return 'style="color:red"';
                                    }
                                },
                            	formatter : function(val, opts, rowdata) {
                            		var str = "";
                            		if(rowdata.status == 1){
                            			str="<spring:message code="message.button.start"/>";
                            		}
                            		if(rowdata.status == 2){
                            			str="<spring:message code="message.button.stop"/>";
                            		}
                            		if(rowdata.status == 3){
                            			str="<spring:message code="message.button.combine"/>";
                            		}
                            		return str;
                            	}
                            },
                            { name: 'updDatetime', width: 40,align:"center",hidden:true,sortable: false }
                ],
                rowNum: 20,
                rowList: [10, 20, 50, 100],
                rownumbers: true,
                pager: "#gridpage",
                multiselect: true, 
                viewrecords: true,
                gridComplete: function(){
                	var page = $("#gridlist").jqGrid('getGridParam','page');
            		var rows = $('#gridlist').getGridParam("rowNum");
            		var maxnum = (rows*page).toString();
            		var len = (maxnum.length)*10;
            		$('.jqgfirstrow').find('td').eq(0).css('width',len+'px');
                	$('#gridlist_rn').css('width',len+'px');
                	
                	//单条数据自动选中
                	var rowIds = $("#gridlist").jqGrid('getDataIDs');
                	if(rowIds.length==1){
                		$("#"+rowIds[0]).click();
                	}
                },
                caption: "<spring:message code="message.list.compgroupStdComplist"/>  <spring:message code="message.listForm.jiTuanBianMa"/>：${compGroup.compGroupCode} <spring:message code="message.listForm.jiTuanMingCheng"/>：${compGroup.compGroupName}",
                jsonReader: {
                    repeatitems: false,
                    id: "compId"
                }
            });
            $("#gridlist").jqGrid('navGrid', '#gridpage', { add: false, edit: false, del: false, search: false, refresh: false });
            $(window).trigger("resize");
            

        $("#gridlist1").jqGrid({
            url: "compListNotGJson.html",
            mtype: "POST",
            datatype: "json",
            autowidth: true,
            height: 270,
            width: 100,
            shrinkToFit: false,
            colNames: ['<spring:message code="message.listForm.qiYeBianMa"/>',
                       '<spring:message code="message.listForm.qiYeMingCheng"/>',
                       '<spring:message code="message.listForm.zuZhiJiGouDaiMa"/>',
                       '<spring:message code="message.listForm.qiYeZhuCeLeiXing"/>'],
            colModel: [
						{ name: 'compCode', width: 140,align:"center" ,sortable: false,hidden:true},
						{ name: 'compName', width: 250,align:"center",sortable: false },
						{ name: 'orgCode', width: 160,align:"center",sortable: false },
						{ name: 'compType', width: 120,align:"center",sortable: false,
							formatter:function(val,opts,rowdata){
								var str="";
								if(val==1){
									str="<spring:message code="message.listForm.shengChanQiYe"/>";
								}else if(val==2){
									str="<spring:message code="message.model.peiSongQiYe"/>";
								}
								return str;
						}}
             ],
            rowNum: 20,
            rowList: [10, 20, 50, 100],
            rownumbers: true,
            pager: "#gridpage1",
            //multiselect: true, 
            viewrecords: true,
            gridComplete: function(){
            	var page = $("#gridlist1").jqGrid('getGridParam','page');
        		var rows = $('#gridlist1').getGridParam("rowNum");
        		var maxnum = (rows*page).toString();
        		var len = (maxnum.length)*10;
        		$($('.jqgfirstrow')[1]).find('td').eq(0).css('width',len+'px');
            	$('#gridlist1_rn').css('width',len+'px');
            	
            	//单条数据自动选中
            	var rowIds = $("#gridlist1").jqGrid('getDataIDs');
            	if(rowIds.length==1){
            		$("#"+rowIds[0]).click();
            	}
            },
            caption: "<spring:message code="message.listForm.xiaShuQiYe"/><spring:message code="message.lable.select"/>",
            jsonReader: {
                repeatitems: false,
                id: "compId"
            }
        });
        $("#gridlist1").jqGrid('navGrid', '#gridpage1', { add: false, edit: false, del: false, search: false, refresh: false });
        //$(window).trigger("resize");
        });    
        function edit(compId1, compCode, compName, status){
              var compId = compId1;
              window.location.href = "${ctx}/stdCompinfo/stdCompinfoEditJsp.html?compId="+compId+"";
        }
      //tingyong
		function batchChangeStatus(status) {
				var msg = "<spring:message code="message.button.stop"/>";
				var url = "${ctx}/stdCompinfo/enable.html";
				if(status == 1){
					msg = "<spring:message code="message.button.start"/>";
					url = "${ctx}/stdCompinfo/disable.html";
				}
			var rowIds = $("#gridlist").jqGrid("getGridParam", "selarrrow") || [];
			if (rowIds.length <= 0) {
				$.alert("<spring:message code="message.lable.pleaseSelect"/>"+msg+"<spring:message code="message.lable.de"/><spring:message code="message.list.compinfoStdMergelist"/>", "warn");
				return;
			}
			
			// -----begin
			var data = "";
			var list = [];
			for(var i = 0;i<rowIds.length;i++){
				var sta =  $("#gridlist").jqGrid('getRowData',rowIds[i]);
				if(sta.status != msg){
					var compName = sta.compName;
					
					data += compName+",";
					list.push({"compId":rowIds[i], "status":status});
				}else{
					
				}  
			}
			if(data){
				data = data.substring(0,data.length-1);
			}else{
				$.alert("<spring:message code="message.lable.ninXuanZe"/><spring:message code="message.list.compinfoStdMergelist"/><spring:message code="message.lable.yiJingShi"/>"+msg+"<spring:message code="message.lable.zhuangTaiGTH"/>", "warn");
				return;
			}
			// -----end
			$.HN.message.confirm("<spring:message code="message.lable.OKYES"/>"+msg+"<spring:message code="message.lable.yiXia"/><spring:message code="message.list.compinfoStdMergelist"/><spring:message code="message.lable.ma"/><br/>"+data, '', '').on(function (e) {
	            if (e) {
			$.post(url, {
				"array" : json.jsonToString(list)
			}, function(result) {
				if (result.success) {
					$.alert("<spring:message code="message.HN.alert.chengGong"/>"+msg+result.conditions.sum+"<spring:message code="message.lable.tiao"/>！", "success");
					var page = $("#gridlist").jqGrid('getGridParam','page');
					searchForPage(page);
				} else {
					$.alert(result.msg || msg+"<spring:message code="message.HN.alert.shibai"/>！", "error");
				}
			}, "json");
	            }
			});
			}
       
        function editSubComp() {
        	$('#sCompName').val("");
			$('#editSubComp').modal({
				keyboard : true
			});
			setTimeout("$('#sCompName').focus()",500);//加载页面光标在第一个查询框内
			search();
		}
        
        
    	function search(page) {
    		var name = $.trim($("#sCompName").val());
    		$("#gridlist1").jqGrid('setGridParam',{  
    			mtype: "POST",
    	        datatype:'json',
    	        postData:{"name":name},
    	        page : (page || 1)
    	    }).trigger("reloadGrid"); //重新载入  
    	}
    	function searchForPage(page) {
    		
    		var name = $.trim($("#compName").val());
    		$("#gridlist").jqGrid('setGridParam',{  
    			mtype: "POST",
    	        datatype:'json',
    	        postData:{ "compName":name,"tid" : "${compGroup.compGroupId}"},
    	        page : (page || 1)
    	    }).trigger("reloadGrid"); //重新载入  
    	}
        function batchGroupAddComp(groupId){
        	var rowId = $("#gridlist1").jqGrid("getGridParam", "selrow") || [];

    		if (rowId.length <= 0) {
    			$.alert("<spring:message code="message.lable.pleaseSelect"/><spring:message code="message.listForm.guanlian"/><spring:message code="message.lable.de"/><spring:message code="message.list.compinfoStdMergelist"/>！", "warn");
    			return;
    		}
    		var list = [];
			list.push({"compId":rowId,"compGroupId":groupId});
			$.HN.message.confirm("<spring:message code="message.lable.OKYES"/><spring:message code="message.listForm.guanlian"/><spring:message code="message.lable.ma"/>", '', '').on(function (e) {
	            if (e) {
    		submitBatchGroupAddComp(list);
	            }
			});
        }
        function groupDelComp(){
        	var rowIds = $("#gridlist").jqGrid("getGridParam", "selarrrow") || [];
    		if (rowIds.length <= 0) {
    			$.alert("<spring:message code="message.lable.pleaseSelect"/><spring:message code="message.listForm.guanlian"/><spring:message code="message.lable.de"/><spring:message code="message.list.compinfoStdMergelist"/>！", "warn");
    			return;
    		}
    		var list = [];
    		var data = "";
    		for (var i=0; i<rowIds.length; i++) {
    			rowId = rowIds[i];
    			var sta =  $("#gridlist").jqGrid('getRowData',rowId);
    			var compName = sta.compName;
				data += compName+",";
    			list.push({"compId":rowId});
    		}
    		data = data.substring(0,data.length-1);
    		$.HN.message.confirm("<spring:message code="message.lable.OKYES"/><spring:message code="message.button.cancel"/><spring:message code="message.lable.yiXia"/><spring:message code="message.list.compinfoStdMergelist"/><spring:message code="message.lable.de"/><spring:message code="message.listForm.guanlian"/><spring:message code="message.lable.ma"/><br/>"+data, '', '').on(function (e) {
	            if (e) {
	            	submitBatchGroupAddComp(list);
	            }
			});
    		
        	
        }
    	function submitBatchGroupAddComp(list){

           	$.ajax({
				type:"POST",
				url:"batchGroupAddComp.html",
				data:{"compinfos":JSON.stringify(list)},
				dataType:"json",
				success:function(returnData){
					if (returnData.success == true) {
	    				$("#editSubComp").modal('hide');
	    				$("#gridlist").jqGrid().trigger("reloadGrid");
	    				$.alert("<spring:message code="message.HN.alert.success"/>",  "success");
	    			} else {
	    				$.alert(result.msg || "<spring:message code="message.HN.alert.fail"/>", "error");
	    			}
				}
			});
        	
        }
    	
        
    </script>
</body>
</html>









